/*
 * Copyright (c) 2018-2999 湖南洛云网络科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.live.platform.controller;

import com.yami.shop.live.comment.model.LiveRoomProd;
import com.yami.shop.live.comment.service.LiveRoomProdService;
import com.yami.shop.common.annotation.SysLog;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 *
 *
 * @author lhd
 * @date 2020-08-05 08:53:17
 */
@RestController
@AllArgsConstructor
@RequestMapping("/live/liveRoomProd" )
public class LiveRoomProdController {

    private final LiveRoomProdService liveRoomProdService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param liveRoomProd
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<LiveRoomProd>> getLiveRoomProdPage(PageParam<LiveRoomProd> page, LiveRoomProd liveRoomProd) {
        return ResponseEntity.ok(liveRoomProdService.page(page, new LambdaQueryWrapper<LiveRoomProd>()));
    }


    /**
     * 通过id查询
     * @param roomProdId id
     * @return 单个数据
     */
    @GetMapping("/info/{roomProdId}" )
    public ResponseEntity<LiveRoomProd> getById(@PathVariable("roomProdId") Long roomProdId) {
        return ResponseEntity.ok(liveRoomProdService.getById(roomProdId));
    }

    /**
     * 新增
     * @param liveRoomProd
     * @return 是否新增成功
     */
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('live:liveRoomProd:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid LiveRoomProd liveRoomProd) {
        return ResponseEntity.ok(liveRoomProdService.save(liveRoomProd));
    }

    /**
     * 修改
     * @param liveRoomProd
     * @return 是否修改成功
     */
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('live:liveRoomProd:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid LiveRoomProd liveRoomProd) {
        return ResponseEntity.ok(liveRoomProdService.updateById(liveRoomProd));
    }

    /**
     * 通过id删除
     * @param roomProdId id
     * @return 是否删除成功
     */
    @SysLog("删除" )
    @DeleteMapping("/{roomProdId}" )
    @PreAuthorize("@pms.hasPermission('live:liveRoomProd:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long roomProdId) {
        return ResponseEntity.ok(liveRoomProdService.removeById(roomProdId));
    }

}
